package com.cat.recruit.common.constant;

import java.util.*;

/**
 * 用户状态常量类
 */
public class UserStatus {
    // 未报名
    public static final String UNENROLLED = "未报名";
    // 已淘汰
    public static final String WITHDRAWN = "已淘汰";
    // 已报名
    public static final String ENROLLED = "已报名";
    // 即将初面
    //public static final String WILL_INTERVIEW = "初面进行中";
    // 待初面
    //public static final String START_INTERVIEW = "待预约初面";
    // 已预约初面
    public static final String ALREADY_INTERVIEW = "初面";
    // 初面通过
    public static final String INTERVIEW_PASSED = "初面通过";
    // 一轮考核进行中
    //public static final String FIRST_ROUND_AUDITING = "一轮考核进行中";
    // 待预约一面
    //public static final String WAIT_FIRST_INTERVIEW = "待预约一面";
    // 已预约一面
    public static final String ALREADY_FIRST_INTERVIEW = "一面";
    // 一轮考核通过
    public static final String FIRST_ROUND_AUDIT_PASSED = "一轮考核通过";
    // 二轮考核进行中
    //public static final String SECOND_ROUND_AUDITING = "二轮考核进行中";
    // 待预约二面
    //public static final String WAIT_SECOND_INTERVIEW = "待预约二面";
    // 已预约二面
    public static final String ALREADY_SECOND_INTERVIEW = "二面";
    // 二轮考核通过
    public static final String SECOND_ROUND_AUDIT_PASSED = "二轮考核通过";
    // 已通过所以考核
    public static final String PASSED = "已通过";

    /**
     * 所有可访问的用户状态列表
     */
    public static final List<String> USER_STATUS_LIST = List.of(
            UNENROLLED,
            WITHDRAWN,
            ENROLLED,
            //WILL_INTERVIEW,
            //START_INTERVIEW,
            ALREADY_INTERVIEW,
            INTERVIEW_PASSED,
            //FIRST_ROUND_AUDITING,
            //WAIT_FIRST_INTERVIEW,
            ALREADY_FIRST_INTERVIEW,
            FIRST_ROUND_AUDIT_PASSED,
            //SECOND_ROUND_AUDITING,
            //WAIT_SECOND_INTERVIEW,
            ALREADY_SECOND_INTERVIEW,
            SECOND_ROUND_AUDIT_PASSED,
            PASSED
    );

    /**
     * 考核类型在用户状态列表中的起始索引
     */
    public static final Map<String, Integer> ACCESS_TYPE_MAP_INDEX = Map.of(
            AccessType.FIRST_INTERVIEW, 3,
            AccessType.FIRST_ROUND_AUDIT, 5,
            AccessType.SECOND_ROUND_AUDIT, 7
    );

    /**
     * 所有可访问的用户状态集合
     */
    private static final Map<String,Integer> USER_STATUS_MAP;

    static {
        USER_STATUS_MAP = new HashMap<>();
        for (int i = 0; i < USER_STATUS_LIST.size(); i++) {
            USER_STATUS_MAP.put(USER_STATUS_LIST.get(i), i);
        }
    }

    /**
     * 判断用户状态是否可访问
     * @param userStatus 用户状态
     * @return true：可访问；false：不可访问
     */
    public static boolean contains(String userStatus) {
        return USER_STATUS_MAP.containsKey(userStatus);
    }

    /**
     * 根据用户状态判断是否可预约某一考核
     */
    public static boolean canAccess(String userStatus, String accessType) {
        return USER_STATUS_MAP.get(userStatus) == ACCESS_TYPE_MAP_INDEX.get(accessType) - 1;
    }

    /**
     * 用户取消预约某一考核后的状态
     */
    public static String cancelAccess(String accessType) {
        return USER_STATUS_LIST.get(ACCESS_TYPE_MAP_INDEX.get(accessType) - 1);
    }

    /**
     * 用户预约了某一考核后的状态
     */
    public static String appointedAccess(String accessType) {
        return USER_STATUS_LIST.get(ACCESS_TYPE_MAP_INDEX.get(accessType));
    }

    /**
     * 用户通过某一考核后的状态
     */
    public static String passAccess(String accessType) {
        return USER_STATUS_LIST.get(ACCESS_TYPE_MAP_INDEX.get(accessType) + 1);
    }

    /**
     * 用户进行某一考核时的状态
     */
    public static String Accessing(String accessType) {
        return USER_STATUS_LIST.get(ACCESS_TYPE_MAP_INDEX.get(accessType));
    }
}
